package org.zk.dubbo_provider.service.impl;



import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.zk.dubbo_provider.dao.LessionMapper;
import org.zk.entity.AdminBill;
import org.zk.entity.Lession;
import org.zk.service.LessionService;
import com.alibaba.dubbo.config.annotation.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 课节表 服务实现类
 * </p>
 *
 * @author Alicelonely
 * @since 2019-12-11
 */
@Service(timeout = 10000)
@CacheConfig(cacheNames = "lession")
public class LessionServiceImpl implements LessionService {

    @Resource
    private LessionMapper lessionMapper;

    //添加课节
    @Override
    public int addLession(Lession lession) {
        return lessionMapper.addLession(lession);
    }

    //分页查询所有课节
    @Override
    public PageInfo getAllLessionPage(Map<String, Object> map) {
        PageInfo<Lession> pageInfo;
        int pageSize=Integer.parseInt(String.valueOf(map.get("pageSize")));
        int pageNum=Integer.parseInt(String.valueOf(map.get("pageNum")));
        PageHelper.startPage(pageNum,pageSize);
        //2.紧跟的查询就是一个分页查询-必须紧跟.后面的其他查询不会被分页，除非再次调用PageHelper.startPage
        try {
            List<Lession> ls= lessionMapper.getAllLession(map);
            //System.out.println("分页数据："+List);
            //3.使用PageInfo包装查询后的结果,5是连续显示的条数,结果list类型是Page<E>
            pageInfo = new PageInfo<>(ls,pageSize);

        }finally {
            PageHelper.clearPage(); //清理 ThreadLocal 存储的分页参数,保证线程安全
        }
        /*PageInfo page=new PageInfo();
        int count=lessionMapper.queryCount(map);
        page.setTotal(count);
        int pageSize = Integer.parseInt(String.valueOf(map.get("pageSize")));
        page.setPageSize(pageSize);
        int currPage = Integer.parseInt(String.valueOf(map.get("pageNum")));
        page.setPageNum(currPage);

        //计算总页数
        int a ;
        if (count % pageSize > 0) {
            a = count / pageSize + 1;
        } else {
            a = count / pageSize;
        }
        page.setPages(a);

        //开始分页
        PageHelper.startPage(currPage,pageSize);
        List<Lession> ls= lessionMapper.getAllLession(map);
        page.setList(ls);*/
        return pageInfo;
    }


    //课程审核
    @Override
    public int updateLessionState(Lession lession) {
        return lessionMapper.updateLessionState(lession);
    }

    @Override
    public Lession getLessionById(int lessionId) {
        return lessionMapper.getLessionById(lessionId);
    }


    public LessionMapper getLessionMapper() {
        return lessionMapper;
    }

    public void setLessionMapper(LessionMapper lessionMapper) {
        this.lessionMapper = lessionMapper;
    }
}
